import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../api/api_path.dart';
import '../api/network_util.dart';

///验证码provider
final codeProvider = ChangeNotifierProvider((ref) => CodeProvider());
class CodeProvider extends ChangeNotifier{
  int counter = 60;
  Timer? _timer;
  //开始倒计时
  startCountDown(){
    if(_timer?.isActive??false){
      return;
    }else {
      _timer = Timer.periodic(const Duration(seconds: 1), (timer) {
        counter--;
        notifyListeners();
        if (counter == 0) {
          counter = 60;
          timer.cancel();
        }
      });
    }
  }
}